<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/12
 * Time: 15:13
 */

namespace app\api\controller;

use app\api\model\UUser AS UserModel;
use app\api\validate\UserIdCheck;

class My extends Base
{
    /**
     * 用户信息
     * user_id     用户ID
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function userInfo(){
        $user_id = input('user_id');

        $resultUserId = (new UserIdCheck())->goCheck();
        if($resultUserId['status'] == 0) return json(['status' => 0, 'msg' => $resultUserId['msg']]);

        $USER = new UserModel();
        $data = $USER::get($user_id);
        return json(['status' => 200, 'msg' => $data]);
    }

    /**
     * 更新用户信息
     * user_id     用户ID
     * username    用户名
     * user_image  头像
     * @return \think\response\Json
     */
    public function updateUser(){
        $user_id = input('user_id');
        $user_username = input('username');
        $user_image = input('user_image');

        $resultUserId = (new UserIdCheck())->goCheck();
        if($resultUserId['status'] == 0) return json(['status' => 0, 'msg' => $resultUserId['msg']]);

        $update = [
            'user_username' => $user_username,
            'user_image' => $user_image,
            'user_update_time' => createTime()
        ];

        $USER = new UserModel();
        $res = $USER::updateUser(['user_id' => $user_id], $update);
        if($res){
            return json(['status' => 200, 'msg' => $this->doSuccess]);
        }else{
            return json(['status' => 0, 'msg' => $this->systemErr]);
        }

    }
}